package com.lemon.smartsafety.ui.adapter.bind;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.entity.safe.company.CompanyInfo;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/3/29.
 */
public class BindComAdapter extends LemonRcvAdapter<CompanyInfo> {
    private RecyclerTClickListener<CompanyInfo> mListener;

    public BindComAdapter(@Nullable List<CompanyInfo> data) {
        super(data);
    }

    public BindComAdapter(List<CompanyInfo> data, RecyclerTClickListener<CompanyInfo> listener) {
        super(data);
        this.mListener = listener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new BindComItem();
    }

    public class BindComItem implements AdapterItem<CompanyInfo> {

        LinearLayout ripple;
        TextView   itemText;
        TextView   itemSubText;
        ImageView  imageArrow;


        private CompanyInfo mData;
        private int         mPosition;


        @Override
        public int getLayoutResId() {
            return R.layout.item_title_sub_title_arrow;
        }

        @Override
        public void bindViews(View root) {
            ripple = (LinearLayout) root.findViewById(R.id.ripple);
            itemText = (TextView) root.findViewById(R.id.itemText);
            itemSubText = (TextView) root.findViewById(R.id.itemSubText);
            imageArrow = (ImageView) root.findViewById(R.id.imageArrow);
        }

        @Override
        public void setViews() {
            ripple.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });
      /*      ripple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
                @Override
                public void onComplete(RippleView rippleView) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });*/
        }

        @Override
        public void handleData(CompanyInfo data, int position) {
            mData = data;
            mPosition = position;
            itemText.setText(StringUtils.nullValue(data.getCompany_name()));
            itemSubText.setText(StringUtils.nullValue(data.getCompany_code()));
        }
    }
}
